<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>在职司机</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico"> <link href="../css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">

    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>基本 <small>分类，查找</small></h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="table_data_tables.html#">选项1</a>
                            </li>
                            <li><a href="table_data_tables.html#">选项2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="">
                        <a data-toggle="modal" data-target="#myModal" href="javascript:void(0);" class="btn btn-primary ">添加行</a>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr>
                            <th>司机ID</th>
                            <th>司机姓名</th>
                            <th>照片</th>
                            <th>性别</th>
                            <th>生日</th>
                            <th>手机号</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="listBody">
                        </tbody>
                        <tfoot>
                        <tr>
                            <th>司机ID</th>
                            <th>司机姓名</th>
                            <th>照片</th>
                            <th>性别</th>
                            <th>生日</th>
                            <th>手机号</th>
                            <th>操作</th>
                        </tr>
                        </tfoot>
                    </table>
                    <div class="modal inmodal" id="myModal" tabindex="300" role="dialog" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content animated bounceInRight">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" onclick="clearModel()"><span aria-hidden="true" >&times;</span><span class="sr-only">关闭</span>
                                    </button>
                                    <h4 class="modal-title">司机表修改</h4>
                                </div>
                                <div class="modal-body">
                                    <form class="form-group" id="modal-form">
                                        <label>司机</label> <input type="number" name="id" readonly="readonly" class="form-control mDriveId">
                                        <label>司机名</label> <input type="text" name="username" placeholder="用户名" class="form-control mDriverName">
                                        <label>实名</label> <input type="text" name="realname" placeholder="实名" class="form-control mDriverPic">
                                        <label>性别</label>
                                        <input type="radio" checked="" value=0 id="optionsRadios1" name="optionsRadios" >男</label>
                                        <input type="radio" value=1 id="optionsRadios2" name="optionsRadios">女</label>
                                        </br>
                                        </br>
                                        <label>生日</label> <input type="date" name="birth" placeholder="生日" class="form-control mDriverBirth">
                                        <label>手机号</label> <input type="text" name="phone" placeholder="请输入您的手机号" class="form-control mDriverPhone">
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-white" data-dismiss="modal" onclick="clearModel()">关闭</button>
                                    <button type="button" class="btn btn-primary" onclick="submitModal(this)">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.7"></script>



<script src="../js/plugins/jeditable/jquery.jeditable.js"></script>

<!-- Data Tables -->
<script src="../js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>

<!-- 自定义js -->
<script src="../js/content.js?v=1.0.0"></script>


<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        initTable()
    });
    function initTable(){
        var pageNum;
        var htmls='';
        $.ajax({
            url : "/driver1/aliveDriver",
            success:function(data) {
                $("#listBody").html('')
                for (var index in data.data) {
                    let sex;
                    if (data.data[index].driverSex==0){
                        sex="男"
                    }else {
                        sex="女"
                    }
                    htmls +=
                        '<tr className = "gradeX" class="grade">'+
                        '<td class = "id">' + data.data[index].driverId + '</td>' +
                        '<td class="driverName">' + data.data[index].driverName + '</td>' +
                        '<td class="driverPic">' + data.data[index].driverPic + '</td>' +
                        '<td class="center driverSex">' + sex + '</td>' +
                        '<td class="center driverBirth">' + data.data[index].driverBirth + '</td>'+
                        '<td class="center driverPhone">' + data.data[index].driverPhone + '</td>'+
                        '<td class="center">' +
                        '<button class="btn btn-primary" id="update" data-toggle="modal" data-target="#myModal" data-backdrop="false" onClick="initModel(this)">修改</button>' +
                        // '<button class="btn btn-primary" onClick="toDelete(this)">删除</button>' +
                        // '<button class="btn btn-primary" onClick="toFroze(this)">冻结</button>' +
                        '</td>' +
                        '</tr>\n'
                }
                var body=document.getElementById('listBody');
                body.innerHTML = htmls
                $('.dataTables-example').dataTable();
            }
        })
    }
    function initModel(obj){
        var tOj=$(obj).parent().parent();
        const id=parseInt( $(tOj).children(".id").text())
        console.log(id)
        $(".mDriveId").val(id);
        $(".mDriverName").val($(tOj).children(".driverName").text())
        $(".mDriverPic").val($(tOj).children(".driverPic").text())
        const sex= $(tOj).children(".sex").text()
        if(sex=="男"){
            $("#optionsRadios1").prop("checked","checked")
        }else{
            $("#optionsRadios2").prop("checked","checked")
        }
        $(".mDriverBirth").val($(tOj).children(".driverBirth").text())
        $(".mDriverPhone").val($(tOj).children(".driverPhone").text())
        var form=$("#modal-form")
        return form
    }
    function submitModal(obj){
        var form=$("#modal-form")
        var data={
            driverId:$(".mDriveId").val(),
            driverName:$(".mDriverName").val(),
            driverPic:$(".mDriverPic").val(),
            driverBirth:$(".mDriverBirth").val(),
            driverPhone:$(".mDriverPhone").val(),
            driverSex:parseInt($("input[name='optionsRadios']:checked").val()),
        }
        if (data.driverId==null||data.driverId==''){
            addUser(data)
        }else {
            updateUser(data)
        }
    }
    function updateUser(data) {
        console.log("更新")
        $.ajax({
            url : "/driver1/updateDriver",
            type: "POST",
            data: JSON.stringify(data),
            processData: false,  // 不处理数据
            contentType: "application/json;charset=UFT-8",   // 不设置内容类型
            success:function(data){
                initTable()
            }
        })
    }
    function addUser(data) {
        console.log("添加")
        $.ajax({
            url : "/driver1/addDriver",
            type: "POST",
            data: JSON.stringify(data),
            processData: false,  // 不处理数据
            contentType: "application/json;charset=UFT-8",   // 不设置内容类型
            success:function(data){
                initTable()
            }
        })
    }
    function toDelete(obj) {
        parent.layer.open({
            type: 0,
            skin: 'layui-layer-demo', //样式类名
            closeBtn: 1, //不显示关闭按钮
            shift: 2,
            shadeClose: true, //开启遮罩关闭
            content: '确认删除？',
            yes:function () {
                const tOj = $(obj).parent().parent();
                const id = parseInt($(tOj).children(".id").text())
                $.ajax({
                        url: "/driver1/deleteDriver",
                        type: "post",
                        data: {"id": id},
                        success: function () {
                            initTable();
                        }
                    }
                )
            }
    })}
    function toFroze(obj) {
        const tOj = $(obj).parent().parent();
        const id = parseInt($(tOj).children(".id").text())
        $.ajax({
                url:"/driver1/frozeUser",
                type: "post",
                data: {"id":id},
                success: function () {
                    initTable();
                }
            }
        )
    }
    function clearModel(){
        $(".mDriveId").val('');
        $(".mDriverName").val('')
        $(".mDriverPic").val('')
        $(".mDriverBirth").val('')
        $(".mDriverPhone").val('')
    }
</script>

<!--    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>-->
<!--统计代码，可删除-->

</body>

</html>
